//
//  SSFirstPageTravelCityModel.m
//  Travel_World
//
//  Created by dlios on 15/10/14.
//  Copyright © 2015年 TLS. All rights reserved.
//

#import "SSFirstPageTravelCityModel.h"

@implementation SSFirstPageTravelCityModel

+ (NSMutableArray *)titleForSectionByArr:(NSMutableArray *)arr
{
//     NSMutableString *string = [NSMutableString stringWithString:@"商帅"];
//    CFStringTransform((CFMutableStringRef)string, NULL, kCFStringTransformMandarinLatin, NO);
//    CFStringTransform((CFMutableStringRef)string, NULL, kCFStringTransformStripDiacritics, NO);
//  
//    NSLog(@"%@",string);
    
    if (arr.count > 0) {
        
        for (int i = 0; i < arr.count - 1; i++) {
            for (int j = 0; j < arr.count - i - 1; j++) {
                
                SSFirstPageTravelCityModel *cityJ = arr[j];
                SSFirstPageTravelCityModel *cityJ1 = arr[j + 1];
                
                if ([cityJ.pinyin compare:cityJ1.pinyin] > 0) {
                    arr[j] = cityJ1;
                    arr[j + 1] = cityJ;
                }
            }
        }
        
        NSMutableArray *resultArr = [NSMutableArray arrayWithObjects:@"热门", nil];
        NSString *tempPinyin;
        
        for (SSFirstPageTravelCityModel *cityModel in arr) {
            NSString *pinyin = [cityModel.pinyin substringToIndex:1];
            if (![tempPinyin isEqualToString:pinyin]) {
                [resultArr addObject:pinyin.uppercaseString];
                tempPinyin = pinyin;
            }
        }
        
        return resultArr;
        
    } else {
        
        return [NSMutableArray array];
    }
}

+ (NSMutableArray *)cityForSectionByArr:(NSMutableArray *)arr
{
    if (arr.count > 0) {
        
        
        for (int i = 0; i < arr.count - 1; i++) {
            for (int j = 0; j < arr.count - i - 1; j++) {
                
                SSFirstPageTravelCityModel *cityJ = arr[j];
                SSFirstPageTravelCityModel *cityJ1 = arr[j + 1];
                
                if ([cityJ.pinyin compare:cityJ1.pinyin] > 0) {
                    arr[j] = cityJ1;
                    arr[j + 1] = cityJ;
                }
            }
        }
        
        
        NSMutableArray *remenArr = [NSMutableArray array];
        NSMutableArray *reusultArr = [NSMutableArray arrayWithObjects:remenArr, nil];
        NSMutableArray *itme;
        NSString *tempStr;

        
        
        for (SSFirstPageTravelCityModel *cityModel in arr) {
            if ([[cityModel.is_hot description] isEqualToString:@"1"]) {
                [remenArr addObject:cityModel];
            }
        }
        
        for (SSFirstPageTravelCityModel *cityModel in arr) {
            NSString *pinyin = [cityModel.pinyin substringToIndex:1];
            if (![tempStr isEqualToString:pinyin]) {
                itme = [NSMutableArray array];
                [itme addObject:cityModel];
                [reusultArr addObject:itme];
                
                tempStr = pinyin;
            } else {
                [itme addObject:cityModel];
            }
        }
        
        return reusultArr;
    } else {
        
        return [NSMutableArray array];
    }
}

@end
